import { Tooltip } from 'antd';
import pageStyles from '@/common/pageLayout.less';
import { removeDateHmsStr, tooltipLength } from '@/utils';
import { OutInRecordManageAPI } from '../common/type';
import { ColumnsRenderFun, getSorter } from '../../Acommon';

/**
 * 管理页表格配置
 * */
export const ManageTableSwitch = (curRes: Record<string, any>, operateFuns: OutInRecordManageAPI.IOperateAPI) => {
  return [
    {
      title: '申请部门/单位',
      dataIndex: 'createDepartmentName',
      key: 'createDepartmentName',
      visible: true,
      fixed: 'left',
      sorter: (a: any, b: any) => getSorter(a?.createDepartmentName, b?.createDepartmentName),
      width: 150,
      render: (text: string) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '流水号',
      dataIndex: 'applyCode',
      key: 'applyCode',
      visible: true,
      width: 150,
      fixed: 'left',
      sorter: (a: any, b: any) => getSorter(a?.applyCode, b?.applyCode),
      render: (text: string, record: Record<string, any>) => {
        return (
          <a
            onClick={() => {
              operateFuns?.onView(record);
            }}
            style={{ width: '100%' }}
          >
            <Tooltip title={tooltipLength(text, 50)}>
              <span className={pageStyles['over-flow-hidden']}>{text || '--'}</span>
            </Tooltip>
          </a>
        );
      },
    },
    {
      title: '申请人',
      dataIndex: 'createrName',
      key: 'createrName',
      sorter: (a: any, b: any) => getSorter(a?.createrName, b?.createrName),
      width: 150,
      visible: true,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '所属部门',
      dataIndex: 'createDePartmentName',
      key: 'createDePartmentName',
      sorter: (a: any, b: any) => getSorter(a?.createDePartmentName, b?.createDePartmentName),
      visible: true,
      width: 150,
      render: (text: string, record) => ColumnsRenderFun({ text: record?.createDepartmentName, isTooltip: true }),
    },
    {
      title: '出入库类型',
      dataIndex: 'type',
      key: 'type',
      sorter: (a: any, b: any) => getSorter(a?.type, b?.type),
      visible: true,
      width: 150,
      render: (text: string | number) => {
        return text == '0'
          ? '领用出库'
          : text == '1'
          ? '调剂入库'
          : text == '2'
          ? '调剂出库'
          : text == '3'
          ? '退回入库'
          : text == '4'
          ? '登记入库'
          : text == '5'
          ? '借用出库'
          : text == '6'
          ? '归还入库'
          : '--';
      },
    },
    {
      title: '数量',
      dataIndex: 'number',
      key: 'number',
      sorter: (a: any, b: any) => getSorter(a?.number, b?.number),
      visible: true,
      width: 150,
      render: (text: string) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '物资类型',
      dataIndex: 'resourceType',
      key: 'resourceType',
      sorter: (a: any, b: any) => getSorter(a?.resourceType, b?.resourceType),
      visible: true,
      width: 150,
      render: (text: string) => {
        return text === '1' ? '资产' : '材料';
      },
    },
    {
      title: '出入库时间',
      dataIndex: 'createTime',
      key: 'createTime',
      sorter: (a: any, b: any) => getSorter(a?.createTime, b?.createTime),
      visible: true,
      width: 150,
      render: (text: string) => removeDateHmsStr(text) || '--',
    },
  ];
};
